package com.devin.controller;

import com.devin.model.entity.Movie;
import com.devin.repository.MovieRepository;
import com.devin.service.MovieService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Optional;

/**
 *  
 *  @author devin
 *  @date 2020-04-14 11:19
 *  @version 1.0.2
*/

@ResponseBody
@Slf4j
@Controller
public class MovieApi {

    @Autowired
    private MovieService movieService;

    /*
     *  通过id得到当前的电影
     *  @Params  id 电影的id
     *
     * */

    @RequestMapping("/getMovieById")
    public Movie getMovieById(Long movieId){
        log.info("getMovieById");
        return  movieService.getById(movieId);
    }

    /*
    * 通过用户名模糊查询电影
    *
    * */
    @RequestMapping("/search")
    public Page<Movie> search(String key, @PageableDefault(size = 6,page = 0) Pageable pageable){
        log.info(key);
        return movieService.search(key,pageable);
    }


    /*
    * 得到电影列表
    * */

    @RequestMapping("/movieList")
    public Page<Movie> getMovieList(@PageableDefault(size = 6,page = 0,sort = "createDate")Pageable pageable)
    {
        return movieService.listAll(pageable);
    }
}
